﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NutriLeaf.Web.Model;

namespace NutriLeaf.Web.View.Administrator.Tips
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        List<TipCategory> mainCategories;
        List<TipCategory> subCategories;
        List<Tip> tips;

        NutriLeafDBEntities context = new NutriLeafDBEntities();
        protected void Page_Load(object sender, EventArgs e)
        {


            if (Request.QueryString["Category"] == null)
            {
                //call all the tips and all categories
                mainCategories = Core.Tips.Tips.GetParentCategories(ref context);
                subCategories = null;
                tips = Core.Tips.Tips.GetAllNotApprovedTips(ref context);
            }
            else
            {
                int tipCategoryId;
                if (int.TryParse(Request.QueryString["Category"].ToString(), out tipCategoryId))
                {
                    if (subCategories != null)
                    {

                        mainCategories = subCategories;
                    }
                    subCategories = Core.Tips.Tips.GetSubCategories(tipCategoryId, ref context);
                    tips = Core.Tips.Tips.GetAllNotApprovedTips(tipCategoryId, ref context);

                }
                else
                {
                    //error page
                    Response.Redirect(Constants.View.Error.Default);
                }


            }

            MainCategoriesLB.DataSource = mainCategories;
            MainCategoriesLB.DataBind();

            SubCategoriesLB.DataSource = subCategories;
            SubCategoriesLB.DataBind();
        }

        protected void AdminManagetipCategoriesBtn_Click(object sender, EventArgs e)
        {
            Response.Redirect(Constants.View.Admin.Tips.ManageTipCategories);
        }

        protected void WriteTipBtn_Click(object sender, EventArgs e)
        {
            Response.Redirect(Constants.View.Admin.Tips.WriteTip);
        }

        protected void DeleteTipBtn_Click(object sender, EventArgs e)
        {
            Response.Redirect(Constants.View.Admin.Tips.DeleteTip);
        }

        protected void ApproveTipBtn_Click(object sender, EventArgs e)
        {
            Response.Redirect(Constants.View.Admin.Tips.ApproveTip);
        }


    }
}